package top.fzqblog.firstapp;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.net.URI;

/**
 * Created by 抽离 on 2017/8/15 0015.
 */

public class DialActivity extends Activity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialtest);
        Button dialbtn = (Button) findViewById(R.id.dial);
        final EditText editText = (EditText) findViewById(R.id.et);
        dialbtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setData(Uri.parse("tel://" + editText.getText()));
                intent.setAction(Intent.ACTION_DIAL);
                startActivity(intent);
            }
        });

        Button btn_Internet = (Button) findViewById(R.id.btn_internet);
        btn_Internet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.setData(Uri.parse("http://" + editText.getText()));
                intent.setAction(Intent.ACTION_VIEW);
                startActivity(intent);
            }
        });
    }
}
